package com.share.log4j.sample;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

@Component
public class Log4jExample implements CommandLineRunner {
    private static final Logger log = LogManager.getLogger(Log4jExample.class);

    @Override
    public void run(String... args) throws Exception {
        while (true){
            log.info("Start process...");
            try {
                "".getBytes("invalidCharsetName");
            } catch (UnsupportedEncodingException e) {
                log.error("Invalid encoding.", e);
            }
            log.warn("test warn level log.");
            log.info("Process end.");
            log.debug("test debug level log.");
            try {
                Thread.sleep(1 * 1);
            } catch (InterruptedException e) {
                log.error("Thread interrupted.", e);
            }
        }

    }
}
